#-------------------------------------------------------------------------------
# By Daoyu @2010-07-06
#-------------------------------------------------------------------------------
from django.db import models
from django.contrib.auth.models import User
from uncle.users.models import *

class Project(models.Model):
    name = models.CharField(max_length = 30)
    creator = models.ForeignKey(User,related_name='creator', unique = False)
    client = models.ForeignKey(User, related_name='client', unique = False)
    def __unicode__(self):
        return self.name

    in_house_producer = models.CharField(max_length = 40);
    time = models.DateTimeField(auto_now_add = True) #When the project is created.

    description = models.CharField(max_length = 5000)
    city = models.CharField(max_length = 20)
    brand = models.CharField(max_length = 30)    
    
    class Meta:
        ordering = ['name']
    
class Project_safe_url(models.Model):
    project = models.ForeignKey(Project, unique = True)
    expire = models.DateField(auto_now_add = True)
    url = models.CharField(max_length = 30)

#-------------------------------------------------------------------------------
# Last time email statistic.
#-------------------------------------------------------------------------------
class Last_email_sta(models.Model):
    user = models.ForeignKey(User, unique = True)
    time = models.DateTimeField(auto_now_add = True)# When is the last time send statistic email.
    visits = models.IntegerField() # How many visits last time.
    project_counts = models.IntegerField() # How many project included last time.

#-------------------------------------------------------------------------------
# All statistic.
#-------------------------------------------------------------------------------
class Email_sta(models.Model):
    user = models.ForeignKey(User, unique = True)
    time = models.DateTimeField(auto_now_add = True) #When this statistic happens.
    visits = models.IntegerField() #How many visits now.
    project_counts = models.IntegerField() # how many projects included.

#-------------------------------------------------------------------------------
# Project's artist. Mant artist to one project relation.
#-------------------------------------------------------------------------------
class Project_artist(models.Model):
    project = models.ForeignKey(Project, unique = False)
    artist = models.ForeignKey(User, unique = False)
    video = models.CharField(max_length = 75, blank = True) # Daoyu which video is shown for each project.

    def __unicode__(self):
        return self.project.name

#-------------------------------------------------------------------------------
# Client's email. Many to one relation.
#-------------------------------------------------------------------------------
class Project_client_email(models.Model):
    project = models.ForeignKey(Project, unique = False)
    email = models.EmailField() 
    name = models.CharField(max_length = 75, blank = True)       # Kalle: name-field added
    title = models.CharField(max_length = 75, blank = True)     # Kalle: title-field added

    def __unicode__(self):
        return self.email
        return self.name            # Kalle: name-field added
        return self.title           # Kalle: title-field added
#-------------------------------------------------------------------------------
# Where the project's file should be upload to.
#-------------------------------------------------------------------------------
def get_upload_to(instance, filename):
    return 'upload/project/' + str(instance.project.id) + \
    '/' + filename


#===============================================================================
# type: 0 video 1 image 2 attachment 3 webpage, 4 youtube
#===============================================================================
class Basket(models.Model):
    project = models.ForeignKey(Project, unique = False)
    user = models.ForeignKey(User, unique = False)
    def __unicode__(self):
        return "%s<%s>" % (self.title, self.project.name) 
    
    type = models.IntegerField()
    url = models.CharField(max_length = 300, blank = True)
    title = models.CharField(max_length = 50, blank = True)
    text = models.CharField(max_length = 300, blank = True)
    time = models.DateTimeField(auto_now_add = True)
    hide = models.BooleanField()

#-------------------------------------------------------------------------------
# Each basket's mood skill
#-------------------------------------------------------------------------------
class Skill_basket(models.Model):
    skill = models.ForeignKey(Skill)
    basket = models.ForeignKey(Basket)
  
#-------------------------------------------------------------------------------
# Add files to project. And text notes explain what it is.
#-------------------------------------------------------------------------------
class Project_file(models.Model):
    project = models.ForeignKey(Project, unique = False)
    def __unicode__(self):
        return self.project.name

    file = models.FileField(upload_to = get_upload_to, blank = True)
    text = models.CharField(max_length = 200, blank = True)
    title = models.CharField(max_length = 50, blank = True)    
    time = models.DateTimeField(auto_now_add = True)
    show = models.BooleanField()                                    # Kalle: Show-field added    

#-------------------------------------------------------------------------------
# The current project's playing movie.
#-------------------------------------------------------------------------------
class Project_video(models.Model):
    project = models.ForeignKey(Project, unique = False)
    def __unicode__(self):
        return self.project.name

    film = models.CharField(max_length = 110, blank = False)

class Project_youtube(models.Model):
    project = models.ForeignKey(Project, unique = False)
    def __unicode__(self):
        return self.project.name

    youtube = models.CharField(max_length = 110, blank = False)
    youtube_title = models.CharField(max_length = 100, blank = True) # Kalle: text-field added
    youtube_text = models.CharField(max_length = 400, blank = True) # Kalle: text-field added
    show = models.BooleanField()                                    # Kalle: Show-field added